package com.zzs.group.manager;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.zzs.group.manager.command.ExportGroupObjectCommand;
import com.zzs.group.manager.constant.QQNumberConstant;
import net.mamoe.mirai.Bot;
import net.mamoe.mirai.console.command.CommandManager;
import net.mamoe.mirai.console.plugin.jvm.JavaPlugin;
import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescriptionBuilder;
import net.mamoe.mirai.contact.Friend;
import net.mamoe.mirai.contact.Group;
import net.mamoe.mirai.contact.NormalMember;
import net.mamoe.mirai.event.Event;
import net.mamoe.mirai.event.EventChannel;
import net.mamoe.mirai.event.GlobalEventChannel;
import net.mamoe.mirai.event.events.MemberJoinEvent;

import java.util.Date;

public final class Manager extends JavaPlugin {
    public static final Manager INSTANCE = new Manager();

    private Manager() {
        super(new JvmPluginDescriptionBuilder("com.zzs.group.manager", "0.1.0")
                .name("zzs群管")
                .author("zzs")
                .build());
    }

    @Override
    public void onEnable() {
        getLogger().info("zzs群管 Plugin loaded!");
        CommandManager.INSTANCE.registerCommand(new ExportGroupObjectCommand(), true);
        EventChannel<Event> eventEventChannel = GlobalEventChannel.INSTANCE.parentScope(this);
        eventEventChannel.subscribeAlways(MemberJoinEvent.class, g -> {
            Bot bot = g.getBot();
            String groupName = g.getGroup().getName();
            long groupId = g.getGroup().getId();
            NormalMember member = g.getMember();
            long id = member.getId();
            String nick = member.getNick();
            Group group = bot.getGroup(QQNumberConstant.YO_KI_GROUP);
            if (group != null) {
                group.sendMessage(groupName + "(" + groupId + ")" + " 群新加入了 " + nick + "(" + id + ")");
            }
        });
    }
}